package com.cashmama.market.api.infras.enums.error;

import com.fqgj.exception.enums.ErrorCodeEnum;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

public enum OrderRestErrorEnum implements ErrorCodeEnum {

    HAS_NOT_FINISHED_ORDER(30000, "You currently have an unfilled order, please apply for a loan after you have completed", HttpStatus.OK), // 您当前有未完成订单,请在完成后申请借款
    BORROW_CASH_ERROR(30001, "Loan Amount Unlegal", HttpStatus.OK),
    BORROW_PERIOD_ERROR(30002, "Loan Duration Unlegal", HttpStatus.OK),
    FREEZE_ORDER(30003, "Your application failed.Please try again %s days later", HttpStatus.OK),
    NOT_TRANSFERED_ORDER(30004, "There is no pending orders", HttpStatus.OK),
    ORDER_USER_INFO_ERROR(30005, "Current user and billing user do not match", HttpStatus.OK),
    ORDER_BILL_ID_ERROR(30006, "Current bill status is abnormal.Please try again after refreshing", HttpStatus.OK),
    PAY_NOT_FINISHED(30007, "The last transaction is not over.Please Connect customer service if you have any questions.", HttpStatus.OK),
    PAID_ERROR(30008, "Payment is abnormal, if debit, do not repeat payment, please contact customer service to confirm the order payment status", HttpStatus.INTERNAL_SERVER_ERROR),
    PAID_PENDING(30009, "The transaction is being processed, do not repeat payment, please contact customer service to confirm the order payment status", HttpStatus.OK),
    PAID_BANK_PENDING(30010, "Bank payment processing, please be patient", HttpStatus.OK),
    NOT_QUOTA(30011, "You currently have no quota", HttpStatus.OK),
    PAY_CANCLE(30051, "Payment canceled", HttpStatus.OK),

    PROFILE_NOT_FINISHED(30012, "Please improve your personal information first", HttpStatus.OK),
    COUPON_NOT_VALID(30013, "The coupon does not exist or is not valid", HttpStatus.OK),
    QUOTA_NOT_AVALIABLE(30014, "The loan amount does not match the current amount. Your current limit is %s", HttpStatus.OK),
    MOTAN_QUOTA_ERROR(30015, "Failed to get quota", HttpStatus.OK),
    ORDER_NOT_MATCH(30016, "The order does not exist under the product", HttpStatus.OK),
    ORDER_NOT_EXSIT(30017, "Order does not exist", HttpStatus.OK),
    ORDER_BILL_NOT_EXSIT(30018, "There is currently no bill to be repaid", HttpStatus.OK),
    ORDER_EXSIT_IN_SDZZ(30019, "The current application order has not been completed. Please come back after applying", HttpStatus.OK),
    ORDER__SDZZ_SERVICE_EXCEPTION(30020, "The service is busy, please try again later", HttpStatus.OK),
    NO_HIGHMARK(30021, "No High Mark report", HttpStatus.OK),
    TRADE_NO_NOT_EMPTY(30022, "LoanID is empty", HttpStatus.OK),
    PERMIT_14_DAYS(30023, "Please go back to the home page and select a 7 day product", HttpStatus.OK),
    ONE_DAY_ONE_ORDER(30024, "Please come back tomorrow to apply for loan", HttpStatus.OK),
    APPLY_PERMIT(30025, "This product loan quota has been used up. Please choose another product or come back tomorrow to apply", HttpStatus.OK),
    REACH_MAX_APPLY_LIMIT(30031, "Maximum number of applications reached today", HttpStatus.OK),
    UPDATE_NOTE(30032, "goto https://www.rupee-mama.in download new version!", HttpStatus.OK),
    OFFLINE_ORDER_NOT_EXIST(30026, "There is no auditing offline orders", HttpStatus.OK),
    OFFLINE_ORDER_FINISH(30027, "The order has been settled, please return to the home page and refresh", HttpStatus.OK),
    EXTENSION_NOT_PERMIT(30028, "You do not meet the extension conditions at present, please pay normally to increase the loan limit.", HttpStatus.OK),
    OLD_VERSION_SUBMIT_ORDER_NOT_PERMIT(30029, "Sorry, our company has upgraded its service. The app only supports the latest version v1.0.6. The latest version is expected to be put on Google Play on August 11. Please wait.", HttpStatus.OK),
    ORDER_APPLY_NOT_PERMIT_IN_THIS_TIME(30030, "Sorry, the loan application will be open from 06:30 to 24:00. Please wait.", HttpStatus.OK),
    ;

    private Integer code;
    private String desc;
    private HttpStatus httpStatus;

    OrderRestErrorEnum(Integer code, String desc, HttpStatus httpStatus) {
        this.code = code;
        this.desc = desc;
        this.httpStatus = httpStatus;
    }

    public Map<String, Object> map() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("code", code);
        result.put("desc", desc);
        return result;
    }

    public Map<String, Object> map(String message) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("code", code);
        if (message != null) {
            result.put("desc", message + desc);
        }
        return result;
    }

    public String toString() {
        return code + ":" + desc;
    }

    public Integer getCode() {
        return code;
    }

    public OrderRestErrorEnum setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    /****
     * 错误信息
     * @return
     */
    @Override
    public String getMsg() {
        return desc;
    }

    public OrderRestErrorEnum setDesc(String desc) {
        this.desc = desc;
        return this;
    }

    public HttpStatus getHttpStatus() {
        return httpStatus;
    }

    public OrderRestErrorEnum setHttpStatus(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
        return this;
    }
}
